package com.gla.giliair.web.admin;

import com.gla.giliair.entity.Planemodel;
import com.gla.giliair.util.MapGenerator;
import com.gla.giliair.web.BaseController;
import com.gla.giliair.web.vo.PlanemodelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description:
 * @Author: Yingtian qian
 * @Date: 2021/8/25 20:41
 */
@Api(tags = "飞机机型管理模块")
@RestController
@RequestMapping("/api/adminX")
public class AdminPlanemmodelController extends BaseController {
    @ApiOperation(value = "获取全部飞机机型列表", notes = "获取全部飞机机型列表，有多种排序方式", produces = "application/json")
    @GetMapping("/findAllPlanemmodel")
    @ResponseBody
    public Map<String, Object> findAllPlanemmodel(//排序关键词：planemodelId、planemodelName
                                                  // firstClassTotality、businessClassTotality、economyClassTotality
                                                  // createTime、updateTime、isDeleted
                                                  //不填关键词默认按id逆向排序
                                                  @RequestParam(value = "sort", defaultValue = "planemodelId") String sort,
                                                  //正反序只对关键词生效
                                                  @RequestParam(value = "isASC", defaultValue = "false") boolean isASC,
                                                  @RequestParam(value = "showDeleted", defaultValue = "false") boolean showDeleted,
                                                  @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                  @RequestParam(value = "pageSize", defaultValue = "16") Integer pageSize) {
        return planemodelService.findAllPlanemodels(sort, isASC, showDeleted, page, pageSize);
    }

    @ApiOperation(value = "搜索飞机机型列表", notes = "搜索飞机机型列表，有多种排序方式", produces = "application/json")
    @PostMapping("/searchPlanemmodel")
    @ResponseBody
    public Map<String, Object> searchPlanemmodel(//排序关键词：planemodelId、planemodelName
                                                 // firstClassTotality、businessClassTotality、economyClassTotality
                                                 // createTime、updateTime、isDeleted
                                                 //不填关键词默认按id逆向排序
                                                 @RequestParam(value = "sort", defaultValue = "planemodelId") String sort,
                                                 //正反序只对关键词生效
                                                 @RequestParam(value = "isASC", defaultValue = "false") boolean isASC,
                                                 @RequestParam(value = "showDeleted", defaultValue = "false") boolean showDeleted,
                                                 @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                 @RequestParam(value = "pageSize", defaultValue = "16") Integer pageSize,
                                                 //模糊搜索参数：型号
                                                 @RequestBody PlanemodelVO searchParams) {
        return planemodelService.searchPlanemodels(sort, isASC, showDeleted, page, pageSize, searchParams);
    }

    @ApiOperation(value = "添加飞机机型信息", notes = "添加飞机机型信息", produces = "application/json")
    @PostMapping("/addPlanemodel")
    @ResponseBody
    public Map<String, Object> addPlanemodel(@RequestParam("planemodelName") String planemodelName,
                                             @RequestParam(value = "firstClassTotality", required = false) Integer firstClassTotality,
                                             @RequestParam(value = "businessClassTotality", required = false) Integer businessClassTotality,
                                             @RequestParam("economyClassTotality") Integer economyClassTotality) {
        if (!StringUtils.hasText(planemodelName)) {
            return MapGenerator.getRes(500, "请输入飞机机型名称！");
        }
        if (economyClassTotality == null) {
            return MapGenerator.getRes(501, "请输入经济舱总数！");
        }

        Planemodel planemodel = new Planemodel();
        planemodel.setPlanemodelName(planemodelName);
        planemodel.setFirstClassTotality(firstClassTotality);
        planemodel.setBusinessClassTotality(businessClassTotality);
        planemodel.setEconomyClassTotality(economyClassTotality);

        return planemodelService.addPlanemodel(planemodel);
    }

    @ApiOperation(value = "删除飞机机型信息", notes = "删除飞机机型信息，可选择性删除全部相关的静态座位", produces = "application/json")
    @PostMapping("/deletePlanemodel")
    @ResponseBody
    public Map<String, Object> deletePlanemodel(@RequestParam("planemodelId") Long planemodelId,
                                                @RequestParam(value = "isSeatDeleted", defaultValue = "false") boolean isSeatDeleted) {
        if (planemodelId == null) {
            return MapGenerator.getRes(500, "请输入飞机机型id！");
        }
        return planemodelService.deletePlanemodel(planemodelId, isSeatDeleted);
    }
}
